package vn.fpt.snake.controller;

import java.awt.Image;
import java.io.File;
import java.util.List;

import vn.fpt.snake.entity.Settings;
import vn.fpt.snake.ui.BoardViewImpl;
import vn.fpt.snake.ui.HighScoreViewImpl;
import vn.fpt.snake.ui.InstructionViewImpl;
import vn.fpt.snake.ui.OverGameViewImpl;
import vn.fpt.snake.ui.StartupViewImpl;
import vn.fpt.snake.view.Board;

public class GameControllerImpl extends AbstractController {
	public GameControllerImpl() {
		super();
	}
	
	public void switchNewGameView(Board parent) throws Exception{
		if(parent != null){
			parent.removeKeyListener(parent._view);
			parent._view = new BoardViewImpl(parent);
			parent.addKeyListener(parent._view);
		}
	}
	
	public void switchGameOverView(Board parent, int score) throws Exception{
		if(parent != null){
			parent.removeKeyListener(parent._view);
			parent._view = new OverGameViewImpl(parent);	
			((OverGameViewImpl)parent._view).setScore(score);
			parent.addKeyListener(parent._view);
		}
	}
	
	public void switchStartupView(Board parent) throws Exception{
		if(parent != null){
			parent.removeKeyListener(parent._view);
			parent._view = new StartupViewImpl(parent);
			parent.addKeyListener(parent._view);
		}
	}
	
	public void switchHighScoreView(Board parent) throws Exception{
		if(parent != null){
			parent.removeKeyListener(parent._view);
			parent._view = new HighScoreViewImpl(parent);
			parent.addKeyListener(parent._view);
		}
	}
	
	public void switchInstructionView(Board parent) throws Exception{
		if(parent != null){
			parent.removeKeyListener(parent._view);
			parent._view = new InstructionViewImpl(parent);
			parent.addKeyListener(parent._view);
		}
	}
	
	public void exitGame(){
		System.exit(0);
	}

	
	public void pauseGame(Board parent){
		parent.timer.stop();
	}
	
	public void resumeGame(Board parent){
		parent.timer.start();
	}

	public void saveGame() {
		throw new UnsupportedOperationException();
	}

	public void loadGame() {
		throw new UnsupportedOperationException();
	}

	public Settings getSettings(){
		return dataAccess.getSettings();
	}
	
	public Image getImage(String name) throws Exception{
		return dataAccess.getImage(name);
	}
	
	public File getFile(String name) throws Exception{
		return dataAccess.getFile(name);
	}
	
	public List<String> getTextFromFile(File file) throws Exception{
		return dataAccess.getTextFromFile(file);
	}
}
